/*
当庄模式(俱乐部)使用房卡兑换发牌次数的功能界面
*/
var confige = require("confige");
cc.Class({
    extends: cc.Component,

    properties: {
        isInit:false,
    },

    onLoad: function () {

    },

    onInit:function(roomID){
        this.roomID = this.node.getChildByName("uid").getComponent("cc.Label");
        this.curScore = this.node.getChildByName("curScore").getComponent("cc.Label");//当前粮草:100
        this.changeScore = this.node.getChildByName("changeScore").getComponent("cc.Label");
        this.diaLabel = this.node.getChildByName("diaLabel").getComponent("cc.Label");
        this.costNum = this.node.getChildByName("costNum").getComponent("cc.Label");
        this.roomID.string = "包厢号："+roomID;
        this.curChangeScore = 0;
        this.isInit = true;
    },

    btnScoreChangeLayerClick:function(event,customEventData){
        var index = parseInt(customEventData);
        switch(index){
            case 0:
            this.curChangeScore += 10;
            break;
            case 1:
            this.curChangeScore += 100;
            break;
            case 2:
            if(this.curChangeScore >= 10)
                this.curChangeScore -= 10;
            break;
            case 3:
            if(this.curChangeScore >= 100)
                this.curChangeScore -= 100;
            break;
            case 4:
            var self = this;
            pomelo.request("connector.entryHandler.sendData", {"code":"balconyOperation","params":{code : "addDiamond",value : Math.floor(this.curChangeScore*3/10)}}, function(data) {
                console.log("buy diamond !!!!!!");
                console.log(data);
                if(data.flag)
                    pomelo.clientScene.resumeBankerStart();
                self.getDiamond();
            });
            break;
            default:
            break;
        };
        this.changeScore.string = this.curChangeScore;
        this.costNum.string = "消耗房卡数目:" + Math.floor(this.curChangeScore*3/10);
    },
    //获取房间当前可用次数
    getDiamond:function(){
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"houseOwnerCmd","params":{code:"getDiamond"}}, function(data) {
            console.log("getDiamond @@@@@@@@");
            console.log(data);
            self.setRoomDia(data.flag);
        });
    },
    
    setRoomDia:function(roomDiamond){
        this.diaLabel.string = "剩余房卡："+confige.curDiamond;
        this.curScore.string = "当前可用次数：" + roomDiamond;
    },

    showLayer:function(curDiamond){
        if(this.isInit == false)
            this.onInit();
        this.setRoomDia(curDiamond);
        this.node.active = true;
    },

    hideLayer:function(){
        this.node.active = false;
    },
});
